import React, { useContext } from 'react'
import { MyContext } from '../../context/MyContext.tsx'

interface SonProps {
  param: string;

  fun(param: string): string;
}

const Son: React.FC<SonProps> = (props: SonProps) => {
  const context = useContext(MyContext)
  const handleClick: () => void = () => {
    props.fun('ts') // 调用父组件的函数并传递消息
  }
  return (
    <>
      <div>
        <span>父组件传过来的{props.param}</span>

        <button onClick={handleClick}>发送消息给父组件</button>
        <span>context的值{context?.count}</span>
        <button onClick={context?.increment}>Increment</button>
        <button onClick={context?.decrement}>Decrement</button>
      </div>
    </>
  )
}
export default Son
